package com.yunshipei.core.model;

import android.os.Parcel;
import android.os.Parcelable;

public class FilePreviewConfig implements Parcelable {

    public static final int TYPE_ONLINE_PREVIEW = 1;
    public static final int TYPE_MOBILE_DOWNLOAD_PREVIEW = 0;

    private int type;
    private String docConvertServer;
    private boolean isExternalPreview = false;
    private String proxyIP = "";
    private int proxyPort;

    public FilePreviewConfig() {
    }

    private FilePreviewConfig(Parcel in) {
        type = in.readInt();
        docConvertServer = in.readString();
        isExternalPreview = in.readByte() != 0;
        proxyIP = in.readString();
        proxyPort = in.readInt();
    }

    public static final Creator<FilePreviewConfig> CREATOR = new Creator<FilePreviewConfig>() {
        @Override
        public FilePreviewConfig createFromParcel(Parcel in) {
            return new FilePreviewConfig(in);
        }

        @Override
        public FilePreviewConfig[] newArray(int size) {
            return new FilePreviewConfig[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(type);
        dest.writeString(docConvertServer);
        dest.writeByte((byte) (isExternalPreview ? 1 : 0));
        dest.writeString(proxyIP);
        dest.writeInt(proxyPort);
    }

    public int getType() {
        return type;
    }

    public String getDocConvertServer() {
        return docConvertServer;
    }

    public boolean isExternalPreview() {
        return isExternalPreview;
    }

    public void setType(int type) {
        this.type = type;
    }

    public void setDocConvertServer(String docConvertServer) {
        this.docConvertServer = docConvertServer;
    }

    public void setExternalPreview(boolean externalPreview) {
        isExternalPreview = externalPreview;
    }

    public String getProxyIP() {
        return proxyIP;
    }

    public int getProxyPort() {
        return proxyPort;
    }

    public void setProxyIP(String proxyIP) {
        this.proxyIP = proxyIP;
    }

    public void setProxyPort(int proxyPort) {
        this.proxyPort = proxyPort;
    }

    public static class Builder {

        private FilePreviewConfig filePreviewConfig;

        public Builder() {
            filePreviewConfig = new FilePreviewConfig();
        }

        public Builder setType(int type) {
            filePreviewConfig.setType(type);
            return this;
        }

        public Builder setDocConvertServer(String serverUrl) {
            filePreviewConfig.setDocConvertServer(serverUrl);
            return this;
        }

        public Builder setExternalPreview(boolean isExtrenalPreview) {
            filePreviewConfig.setExternalPreview(isExtrenalPreview);
            return this;
        }

        public Builder setFilePreviewServerProxy(String proxyIP, int proxyPort) {
            filePreviewConfig.setProxyIP(proxyIP);
            filePreviewConfig.setProxyPort(proxyPort);
            return this;
        }

        public FilePreviewConfig build() {
            return filePreviewConfig;
        }
    }
}
